package com.softmaker.controller;


import com.softmaker.entity.UserTask;
import com.softmaker.service.UserTaskService;
import com.softmaker.utils.ResultVOUtil;
import com.softmaker.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/usertask")
public class UserTaskController {
    @Autowired
    private UserTaskService service;
    @PostMapping("/addUserTask")
    public Result<String> addUserTask(@RequestBody UserTask userTask){
        if(service.findUserTask(userTask.getUserName(),userTask.getTaskName()) !=null ){
            return ResultVOUtil.success("已经添加了这个任务");
        }
        UserTask userTask1 = service.addUserTask(userTask);
        return ResultVOUtil.success("成功");
    }
    @PostMapping("/delUserTask")
    public Result<String> delUserTask(@RequestBody UserTask userTask){
        if(service.findUserTask(userTask.getUserName(),userTask.getTaskName()) == null){
            return ResultVOUtil.error("没有这个任务");
        }
        service.deleteByUserNameAndTaskId(userTask.getUserName(),userTask.getTaskName());
        return ResultVOUtil.success("成功");
    }
    @GetMapping("/findUserTask")
    public Result<String> findUserTask(@RequestParam("userName") String userName,@RequestParam("taskName") String taskName){
        if (service.findUserTask(userName,taskName)!=null){
            return ResultVOUtil.success("已完成");
        }else {
            return ResultVOUtil.success("未完成");
        }

    }
}
